package org.fisco.bcos.asset.service.impl;



import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

import lombok.SneakyThrows;
import org.fisco.bcos.asset.client.CharityDonationClient;
import org.fisco.bcos.asset.resp.DonationRecord;
import org.fisco.bcos.asset.resp.DonationRecordItem;
import org.fisco.bcos.asset.resp.ProjectDetail;
import org.fisco.bcos.asset.service.parent.CharityService;
import org.fisco.bcos.sdk.abi.datatypes.generated.tuples.generated.Tuple3;
import org.fisco.bcos.sdk.abi.datatypes.generated.tuples.generated.Tuple7;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class CharityServiceImpl implements CharityService {

    @Autowired
    private CharityDonationClient charityDonationClient;

    @SneakyThrows
    @Override
    public ProjectDetail getProjectDetails(BigInteger projectId) {
        return charityDonationClient.getProjectDetails(projectId);
    }

    @SneakyThrows
    @Override
    public List<DonationRecordItem> getDonationRecords(BigInteger projectId) {
        DonationRecord donationRecords = charityDonationClient.getDonationRecords(projectId);
// 创建存储 DonationRecordItem 的列表
        List<DonationRecordItem> recordItems = new ArrayList<>();

// 获取记录数量
        int recordCount = donationRecords.getRecordCount();

// 遍历所有记录并转换为 DonationRecordItem
        for (int i = 0; i < recordCount; i++) {
            DonationRecordItem item = donationRecords.getRecord(i);
            if (item != null) {
                recordItems.add(item);
            }
        }
        return recordItems;
    }

    @SneakyThrows
    @Override
    public BigInteger getUserRole(String userAddress) {
        return charityDonationClient.getUserRole(userAddress);
    }

    @SneakyThrows
    @Override
    public BigInteger getProjectCount() {
        return charityDonationClient.getProjectCount();
    }

    @SneakyThrows
    @Override
    public BigInteger getApplicationCount() {
        return charityDonationClient.getApplicationCount();
    }

    @Override
    public String getContractAddress() {
        return charityDonationClient.getContractAddress();
    }
    @SneakyThrows
    @Override
    public String getCharityOrg() {
        return charityDonationClient.getCharityOrg();
    }
    @SneakyThrows
    @Override
    public String getRegulator() {
        return charityDonationClient.getRegulator();
    }
}